//
//  YMHomeHealthItemCardView.m
//  YMMedical
//
//  Created by y s on 2023/7/19.
//

#import "YMHomeHealthItemCardView.h"

@interface YMHomeHealthItemCardView ()

@property (nonatomic, strong) UIView *vBg;
@property (nonatomic, strong) UIImageView *imgvIcon;
@property (nonatomic, strong) UIImageView *imgvMark;

@property (nonatomic, strong) UILabel *lblName;
@property (nonatomic, strong) UILabel *lblShort;

@end


@implementation YMHomeHealthItemCardView

- (instancetype)init{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark -- UI
- (void)setUI{
    [self addSubview:self.vBg];
    [self.vBg addSubview:self.imgvIcon];
    [self.vBg addSubview:self.imgvMark];
    [self.vBg addSubview:self.lblName];
    [self.vBg addSubview:self.lblShort];
    
    [self.vBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo([SFitUtil fit:18]);
    }];
    [self.imgvIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:11]);
        make.top.mas_equalTo([SFitUtil fit:-18]);
        make.size.mas_equalTo([SFitUtil fitSize:60 height:84]);
    }];
    [self.imgvMark mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.mas_equalTo(0);
        make.size.mas_equalTo([SFitUtil fitSize:32 height:32]);
    }];
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgvIcon.mas_right).offset([SFitUtil fit:8]);
        make.right.mas_equalTo([SFitUtil fit:-8]);
        make.top.mas_equalTo([SFitUtil fit:21]);
    }];
    [self.lblShort mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.lblName);
        make.top.equalTo(self.lblName.mas_bottom).offset([SFitUtil fit:10]);
    }];
}

- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    NSString *shortStr = [SDataUtil stringOf:dict[@"uegppievxbdphngo"]];
    if (shortStr != nil && shortStr.length > 0){
        self.lblShort.text = [NSString stringWithFormat:@"（%@）",shortStr];
    }else{
        self.lblShort.text = @"";
    }
    self.lblName.text = [SDataUtil stringOf:dict[@"ribhfqebw2sqjovu"]];
    
}
- (void)setShowSelect:(BOOL)showSelect{
    _showSelect = showSelect;
    self.imgvMark.hidden = !showSelect;
    if (showSelect){
        self.lblName.textColor = STheme.D12;
        self.lblShort.textColor = STheme.D12;
    }else{
        self.lblName.textColor = STheme.D3;
        self.lblShort.textColor = STheme.D3;
    }
}

#pragma mark -- setter and getter
- (UIView *)vBg{
    if (_vBg == nil){
        _vBg = [[UIView alloc] init];
        _vBg.backgroundColor = STheme.D9;
        _vBg.layer.cornerRadius = 10;
        _vBg.layer.shadowColor = [SUIUtil colorOf:0x831CB5 alpha:0.05].CGColor;
        _vBg.layer.shadowOffset = CGSizeMake(0, 4);
        _vBg.layer.shadowOpacity = 1.0;
        _vBg.layer.shadowRadius = 10;
    }
    return _vBg;
}
- (UIImageView *)imgvIcon{
    if (_imgvIcon == nil){
        _imgvIcon = [[UIImageView alloc] init];
        _imgvIcon.image = [UIImage imageNamed:@"home_banner_pic_left"];
    }
    return _imgvIcon;
}
- (UIImageView *)imgvMark{
    if (_imgvMark == nil){
        _imgvMark = [[UIImageView alloc] init];
        _imgvMark.image = [UIImage imageNamed:@"home_health_item_select_icon"];
        _imgvMark.hidden = YES;
    }
    return _imgvMark;
}
- (UILabel *)lblName{
    if (_lblName == nil){
        _lblName = [[UILabel alloc] init];
        _lblName.textColor = STheme.D3;
        _lblName.font = [SFitUtil fitBoldFont:16];
        _lblName.textAlignment = NSTextAlignmentCenter;
    }
    return _lblName;
}
- (UILabel *)lblShort{
    if (_lblShort == nil){
        _lblShort = [[UILabel alloc] init];
        _lblShort.textColor = STheme.D3;
        _lblShort.font = [SFitUtil fitBoldFont:14];
        _lblShort.textAlignment = NSTextAlignmentCenter;
    }
    return _lblShort;
}


@end
